{include file="common/mainHead"/}
<div class="admin-main fadeInUp animated">
    <blockquote class="layui-elem-quote">
        <a href="{:url('addMenu')}" class="layui-btn layui-btn-small">
            <i class="fa fa-plus"></i> {:lang('add')}菜单
        </a>
        <a  href="javascript:;" onclick="return createMenu();" class="layui-btn layui-btn-small">
            <i class="fa fa-upload"></i> 生成菜单
        </a>
    </blockquote>
    <fieldset class="layui-elem-field">
        <legend>菜单管理</legend>
        <div class="layui-field-box table-responsive">
            <form class="layui-form layui-form-pane">
                <table class="layui-table table-hover">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>主菜单名称</th>
                        <th>菜单类型</th>
                        <th>{:lang('status')}</th>
                        <th>{:lang('order')}</th>
                        <th>菜单操作值</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <!--内容容器-->
                    <tbody id="con">
                    {volist name="wxMenu" id="v"}
                    <tr>
                        <td>{$v.id}</td>
                        <td>{$v.lefthtml}{$v.name}</td>
                        <td>{$v.type}</td>
                        <td>
                            {if condition='$v["open"] eq 1'}
                            <a class="red" href="javascript:;" onclick="return stateyes('{$v.id}');" title="已开启">
                                <div id="zt{$v.id}">
                                    <button class="layui-btn layui-btn-warm layui-btn-mini">状态开启</button>
                                </div>
                            </a>
                            {else/}
                            <a class="red" href="javascript:;" onclick="return stateyes('{$v.id}');" title="已禁用">
                                <div id="zt{$v.id}">
                                    <button class="layui-btn layui-btn-danger layui-btn-mini">状态禁用</button>
                                </div>
                            </a>
                            {/if}
                        </td>
                        <td><input name="{$v.id}" value="{$v.listorder}" class="list_order"/></td>
                        <td>{$v.value}</td>
                        <td>
                            <a href="{:url('editMenu',['id'=>$v['id']])}" class="layui-btn layui-btn-mini">{:lang('edit')}</a>
                            <a href="javascript:;" onclick="return del('{$v.id}')" class="layui-btn layui-btn-mini layui-btn-danger">{:lang('del')}</a>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                    <tfoot>
                        <tr>
                            <td colspan="7">
                                <button type="button" class="layui-btn  layui-btn-small" lay-submit="" lay-filter="sort">{:lang('order')}</button>
                            </td>
                        </tr>
                    </tfoot>
                </table>
            </form>
        </div>
    </fieldset>
</div>
{include file="common/mainFoot"/}
<script>
    layui.use(['form', 'layer'], function() {
        var form = layui.form(), layer = layui.layer;
    });
    function stateyes(id) {
        $.post('{:url("menuState")}', {id: id}, function (data) {
            if (data.status) {
                if (data.info == '状态禁止') {
                    var a = '<button class="layui-btn layui-btn-danger layui-btn-mini">状态禁用</button>'
                    $('#zt' + id).html(a);
                    layer.msg(data.info, {icon: 5});
                    return false;
                } else {
                    var b = '<button class="layui-btn layui-btn-warm layui-btn-mini">状态开启</button>'
                    $('#zt' + id).html(b);
                    layer.msg(data.info, {icon: 6});
                    return false;
                }
            }else{
                layer.msg(data.msg,{time:1000,icon:2});
                return false;
            }
        });
        return false;
    }
    //排序提交
    layui.use(['form', 'layer'], function() {
        var form = layui.form(),layer = layui.layer;
        form.on('submit(sort)', function(data){
            $.post("{:url('menuOrder')}",data.field,function(res){
                if(res.code > 0){
                    layer.msg(res.msg,{time:1000,icon:1},function(){
                        location.href = res.url;
                    });
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            })
        });
    });
    function del(id) {
        layer.confirm('你确定要删除吗？', {icon: 3}, function (index) {
            layer.close(index);
            window.location.href = "{:url('delMenu')}?id=" + id;
        });
    }
    function createMenu() {
        $.post('{:url("createMenu")}', function(data){
            if(data.status==1){
                layer.alert(data.info, {icon: 6});
            }else{
                layer.alert(data.info, {icon: 5});
            }
        });
        return false;
    }
</script>